package com.qn.service;

import com.qn.grpc.protobuf.news.News;
import com.qn.grpc.protobuf.news.NewsRequest;
import com.qn.grpc.protobuf.news.NewsResponse;
import com.qn.grpc.protobuf.news.NewsServiceGrpc;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * grpc客户服务
 *
 * @author qn
 * @date 2023/03/17
 */
@Service
@Slf4j
public class GrpcClientService {

    @GrpcClient("local-grpc-server")
    private NewsServiceGrpc.NewsServiceBlockingStub newsServiceBlockingStub;

    public List<News> list(String data){
        NewsResponse response = newsServiceBlockingStub.list(NewsRequest.newBuilder().setDate(data).build());
        return response.getNewsList();
    }
}